/* GUI CONVERTED from rcsqrp02.p (converter v1.76) Fri May  3 13:22:34 2002 */
/* rcsqrp02.p - SEQUENCE SCHEDULE SHIP TO PLAN VARIANCE RPT             */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.9 $                                                     */
/*V8:ConvertMode=FullGUIReport                                          */
/* REVISION: 9.1   CREATED      : 10/11/99      BY: *N003* Steve Nugent */
/* REVISION: 9.1   LAST MODIFIED: 03/24/00      BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1   LAST MODIFIED: 08/12/00      BY: *N0KP* myb              */
/* $Revision: 1.9 $    BY: Katie Hilbert        DATE: 04/15/02  ECO: *P03J*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */

/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i}




define variable diff_qty            like ld_qty_oh
                                    label "Qty Diff" no-undo.
define variable cum_diff_qty        like ld_qty_oh
                                    label "Cum Qty Diff" no-undo.
define variable so_from             like so_nbr no-undo.
define variable so_to               like so_nbr no-undo.
define variable var_variance        as  decimal format "99"
                                    label "Variance % " no-undo.
define variable var_percent_qty     as  decimal format "ZZZ99"
                                    label "Variance % " no-undo.
define variable var_percent_cum     as  decimal format "ZZZ99"
                                    label "Variance % " no-undo.
define variable wk_percent_qty      as decimal format "999.99" no-undo.
define variable wk_percent_cum      as decimal format "999.99" no-undo.
define variable wk_variance         as decimal format ".99"    no-undo.
define variable var_abc_class       as  character format "x(1)"
                                    label "ABC Class"   no-undo.
define variable wk_del_flag         like mfc_logical    no-undo.
define variable wk_delta            like schd_discr_qty no-undo.
define variable wk_upper_lmt        like schd_discr_qty no-undo.
define variable wk_lower_lmt        like schd_discr_qty no-undo.
define variable part_from           like sod_part       no-undo.
define variable part_to             like sod_part       no-undo.
define variable shipfrom_from       like scx_shipfrom   no-undo.
define variable shipfrom_to         like scx_shipfrom   no-undo.
define variable shipto_from         like so_ship        no-undo.
define variable shipto_to           like so_ship        no-undo.
define variable plan_schd_discr_qty like schd_discr_qty no-undo.
define variable ship_schd_discr_qty like schd_discr_qty no-undo.
define variable new_date            like rcsd_date      no-undo.
define variable saved_date          like rcsd_date      no-undo.

define temp-table ship_schd_day no-undo
   field ssd_nbr       like so_nbr
   field ssd_line      like schd_line
   field ssd_week_date like schd_date
   field ssd_part      like sod_part
   field ssd_desc      like pt_desc1
   field ssd_rlid      like schd_rlse_id   label "Ship/Plan Release ID"
   field ssd_seq_rlid  like schd_rlse_id   label "Sequence Release ID"
   field ssd_plan_flag like mfc_logical
   field ssd_ship_flag like mfc_logical
   field ssd_schd_qty  like schd_discr_qty
                       label "S/P Discrete Qty!Seq Discrete Qty"
   field ssd_schd_cum  like schd_cum_qty   label "S/P Cum Qty!Seq Cum Qty"
   field ssd_seq_qty   like schd_discr_qty
   field ssd_seq_cum   like schd_cum_qty
   field ssd_interval  like schd_interval
   field ssd_cum_qty   like schd_cum_qty
   field ssd_pct_qty   as decimal
                       format "ZZZ99"
                       label "Variance % "
   field ssd_pct_cum   as decimal
                       format "ZZZ99"
                       label "Variance % "
   field ssd_shipfrom  like rcsd_shipfrom
   field ssd_shipto    like rcsd_shipto
   index ssd_index1    is unique primary
      ssd_nbr
      ssd_line
      ssd_week_date.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
shipfrom_from        colon 22 label "Ship-From"
   shipfrom_to          colon 50 label {t001.i}
   shipto_from          colon 22
   shipto_to            colon 50 label {t001.i}
   part_from            colon 22
   part_to              colon 50 label {t001.i}
   so_from              colon 22 label "Order"
   so_to                colon 50 label {t001.i}
   skip (1)
   var_variance         colon 22
   var_abc_class        colon 22
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = &IF (DEFINED(SELECTION_CRITERIA) = 0)
  &THEN " Selection Criteria "
  &ELSE {&SELECTION_CRITERIA}
  &ENDIF .
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

{wbrp01.i}


/*GUI*/ {mfguirpa.i true "printer" 132 " " " " " "  }

/*GUI repeat : */
/*GUI*/ procedure p-enable-ui:


   display
      var_variance with frame a.

   if so_to       = hi_char then so_to       = "".
   if part_to     = hi_char then part_to     = "".
   if shipfrom_to = hi_char then shipfrom_to = "".
   if shipto_to   = hi_char then shipto_to   = "".

   if c-application-mode <> 'WEB' then
   
run p-action-fields (input "display").
run p-action-fields (input "enable").
end procedure. /* p-enable-ui, replacement of Data-Entry GUI*/

/*GUI*/ procedure p-report-quote:


   {wbrp06.i &command = update
      &fields = "  shipfrom_from shipfrom_to shipto_from
        shipto_to part_from part_to so_from
        so_to var_variance var_abc_class"
      &frm = "a"}

   if (c-application-mode <> 'WEB')  or
      (c-application-mode = 'WEB' and
      (c-web-request begins 'DATA'))
   then do:
      bcdparm = "".
      {mfquoter.i shipfrom_from}
      {mfquoter.i shipfrom_to}
      {mfquoter.i shipto_from }
      {mfquoter.i shipto_to }
      {mfquoter.i part_from   }
      {mfquoter.i part_to     }
      {mfquoter.i so_from     }
      {mfquoter.i so_to       }
      {mfquoter.i var_variance }
      {mfquoter.i var_abc_class }

      if so_to       = "" then so_to       = hi_char.
      if part_to     = "" then part_to     = hi_char.
      if shipfrom_to = "" then shipfrom_to = hi_char.
      if shipto_to   = "" then shipto_to   = hi_char.
   end.  /* do */

   /* OUTPUT DESTINATION SELECTION */
   
/*GUI*/ end procedure. /* p-report-quote */
/*GUI - Field Trigger Section */

/*GUI MFSELxxx removed*/
/*GUI*/ procedure p-report:
/*GUI*/   {gpprtrpa.i "printer" 132 " " " " " " " " }
/*GUI*/   mainloop: do on error undo, return error on endkey undo, return error:

define buffer ship_mstr       for sch_mstr.
define buffer ship_det        for schd_det.


   {mfphead2.i}

   /* MAIN LOOP */

   assign
      wk_variance = var_variance / 100.

   for each so_mstr
      where (so_nbr >= so_from and so_nbr <= so_to) and
            (so_ship >= shipto_from and so_ship <= shipto_to) and
            so_seq_order no-lock,
      each sod_det
         where so_nbr = sod_nbr and
               (sod_curr_rlse_id[1] <> '' or
                sod_curr_rlse_id[2] <> '') and
               (sod_part >= part_from and sod_part <= part_to) and
               (sod_site >= shipfrom_from and sod_site <= shipfrom_to)
         no-lock,
      each pt_mstr
         where pt_part = sod_part no-lock:

      if var_abc_class <> "" then
         if pt_abc <> var_abc_class then
            next.

      if sod_curr_rlse_id[2] <> "" then do:
         for last sch_mstr where sch_rlse_id = sod_curr_rlse_id[2]
            and sch_type = 2
            and sch_nbr = so_nbr
            and sch_line = sod_line
            use-index sch_cr_date
         no-lock:
         end.
         if not available sch_mstr then
            next.
      end.
      else do:
         for last sch_mstr where sch_rlse_id = sod_curr_rlse_id[1]
            and   sch_type = 1
            and   sch_nbr = so_nbr
            and   sch_line = sod_line
            use-index sch_cr_date
         no-lock:
         end.
         if not available sch_mstr then
            next.
      end.

      saved_date = ?.

      for each schd_det
          where sch_type = schd_type
            and schd_nbr = sch_nbr
            and schd_line = sch_line
            and schd_rlse_id = sch_rlse_id
         no-lock
            break
            by schd_type
            by schd_nbr
            by schd_line
            by schd_rlse_id
            by schd_date:

         {gprun.i ""rswmd.p""
            "(input schd_date, input yes, output new_date)"}

         if new_date <> saved_date then do:

            create ship_schd_day.
            assign
               ssd_nbr       = schd_nbr
               ssd_line      = schd_line
               ssd_week_date = new_date
               ssd_part      = sod_part
               ssd_desc      = pt_desc1
               ssd_rlid      = schd_rlse_id
               ssd_seq_rlid  = ""
               ssd_plan_flag = (if schd_type = 1 then yes else no)
               ssd_ship_flag = (if schd_type = 2 then yes else no)
               ssd_schd_qty  = schd_discr_qty
               ssd_schd_cum  = schd_cum_qty
               ssd_seq_qty   = 0
               ssd_seq_cum   = 0
               ssd_interval  = schd_interval
               ssd_cum_qty   = schd_cum_qty
               ssd_shipfrom  = sod_site
               ssd_shipto    = so_ship
               saved_date    = new_date.

            if recid(ship_schd_day) = -1 then.
         end. /* do */

         else
            assign
               ssd_schd_qty = ssd_schd_qty + schd_discr_qty
               ssd_schd_cum = schd_cum_qty.

      end. /* for each schd_det */

      for last rcs_mstr where
         rcs_shipto = so_ship  and
         rcs_shipfrom = sod_site and
         rcs_active
         use-index rcs_index3
      no-lock:
      end.
      if available rcs_mstr
      then do:

         for each rcsd_det where
               rcsd_shipto = rcs_shipto     and
               rcsd_shipfrom = rcs_shipfrom and
               rcsd_rlse_id = rcs_rlse_id   and
               rcsd_order = sod_nbr         and
               rcsd_line = sod_line
            no-lock
               break
               by rcsd_order
               by rcsd_line
               by rcsd_rlse_id
               by rcsd_date:

            {gprun.i ""rswmd.p""
               "(input rcsd_date, input yes, output new_date)"}

            for first ship_schd_day
               where ssd_nbr       = rcsd_order
               and   ssd_line      = rcsd_line
               and   ssd_week_date = new_date
            exclusive-lock:
            end. /* for first */
            if available ship_schd_day
            then
               assign
                  ssd_seq_qty = ssd_seq_qty + rcsd_discr_qty
                  ssd_seq_cum = rcsd_cum_qty
                  ssd_seq_rlid = rcsd_rlse_id.

            else
            if ship_schd_discr_qty <> 0
            then do:
               create ship_schd_day.
               assign
                  ssd_nbr       = rcsd_order
                  ssd_line      = rcsd_line
                  ssd_week_date = new_date
                  ssd_part      = sod_part
                  ssd_desc      = pt_desc1
                  ssd_rlid      = ""
                  ssd_seq_rlid  = rcsd_rlse_id
                  ssd_plan_flag = no
                  ssd_ship_flag = no
                  ssd_schd_qty  = 0
                  ssd_schd_cum  = 0
                  ssd_seq_qty   = rcsd_discr_qty
                  ssd_seq_cum   = rcsd_cum_qty
                  ssd_cum_qty   = rcsd_cum_qty
                  ssd_shipfrom  = rcsd_shipfrom
                  ssd_shipto    = rcsd_shipto.
            end. /* else if.. do */
         end. /* for each rcsd_det */
      end. /* if available rcs_mstr */

      for each ship_schd_day
         exclusive-lock:
         wk_del_flag = no.
         if ssd_schd_qty = ssd_seq_qty then
            wk_del_flag = yes.
         if not ssd_plan_flag
            and not ssd_ship_flag then
            wk_del_flag = yes.
         if ssd_seq_rlid = "" then
            wk_del_flag = yes.
         if wk_del_flag = no
         then do:
            assign
               wk_delta = ssd_schd_qty * wk_variance
               wk_upper_lmt = ssd_schd_qty + wk_delta
               wk_lower_lmt = ssd_schd_qty - wk_delta.

            if  ssd_seq_qty < wk_upper_lmt
               and ssd_seq_qty > wk_lower_lmt
            then wk_del_flag = yes.
         end. /* do */

         if wk_del_flag then do:
            delete ship_schd_day.
         end.
         else do:
            assign
               diff_qty = ssd_schd_qty - ssd_seq_qty
               cum_diff_qty = ssd_schd_cum - ssd_seq_cum.

            if diff_qty > 0 then
               wk_percent_qty = diff_qty / ssd_schd_qty.
            else
               assign
                  diff_qty = diff_qty * -1
                  wk_percent_qty = diff_qty / ssd_schd_qty.

            if ssd_schd_qty = 0 then
               wk_percent_qty = 1.
            if cum_diff_qty > 0 then
               wk_percent_cum = cum_diff_qty / ssd_schd_cum.
            else
               assign
                  cum_diff_qty = cum_diff_qty * -1
                  wk_percent_cum = cum_diff_qty / ssd_schd_cum.

            if ssd_schd_cum = 0 then
               wk_percent_cum = 1.

            assign
               ssd_pct_qty = wk_percent_qty * 100
               ssd_pct_cum = wk_percent_cum * 100.
         end. /* else do */
      end. /* for each */

      FORM /*GUI*/ 
      with STREAM-IO /*GUI*/  frame ssdhead down width 132 no-box.

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame ssdhead:handle).

      FORM /*GUI*/ 
      with STREAM-IO /*GUI*/  frame ssddet down width 132 no-box.

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame ssddet:handle).

      clear frame ssdhead all no-pause.
      clear frame ssddet all no-pause.

      for each ship_schd_day
         exclusive-lock
            break
            by ssd_shipfrom
            by ssd_shipto
            by ssd_nbr
            by ssd_line
            by ssd_week_date:
         if first-of (ssd_line) then do:
            display
               ssd_shipfrom column-label "Ship-From!Ship-To"
               ssd_nbr      column-label "Order!Line"
               ssd_part
               ssd_desc
               ssd_rlid     column-label "Ship/Plan Release ID!Sequence Release ID"
            with width 132
               frame ssdhead STREAM-IO /*GUI*/ .

            down 1 with frame ssdhead.

            display
               ssd_shipto   @ ssd_shipfrom
               ssd_line     @ ssd_nbr
               ssd_seq_rlid @ ssd_rlid
            with frame ssdhead STREAM-IO /*GUI*/ .

            down 2 with frame ssdhead.

         end.  /* if first-of (ssd_line) */

         assign
            diff_qty = ssd_schd_qty - ssd_seq_qty
            cum_diff_qty = ssd_schd_cum - ssd_seq_cum.

         display
            space(10)
            ssd_week_date
            ssd_schd_qty column-label "S/P Discrete Qty!Seq Discrete Qty"
            diff_qty     when (diff_qty <> 0)
            ssd_pct_qty  when (ssd_pct_qty <> 0)
            space(8)
            ssd_schd_cum column-label "S/P Cum Qty!Seq Cum Qty"
            cum_diff_qty when (cum_diff_qty <> 0)
            ssd_pct_cum  when (ssd_pct_cum <> 0)
         with width 132
            frame ssddet STREAM-IO /*GUI*/ .

         down 1 with frame ssddet.

         display
            ssd_seq_qty @ ssd_schd_qty
            ssd_seq_cum @ ssd_schd_cum
         with frame ssddet STREAM-IO /*GUI*/ .

         down 2 with frame ssddet.

         delete ship_schd_day.
      end. /* for each */
   end. /* for each so_mstr */

   /* REPORT TRAILER */
   
/*GUI*/ {mfguitrl.i} /*Replace mfrtrail*/

/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/


end.  /* repeat */

{wbrp04.i &frame-spec = a}

/*GUI*/ end procedure. /*p-report*/
/*GUI*/ {mfguirpb.i &flds=" shipfrom_from shipfrom_to shipto_from shipto_to part_from part_to so_from so_to var_variance var_abc_class "} /*Drive the Report*/
